﻿using Link_eLab.SqlSugar.Extension;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Nancy.Json;
using Newtonsoft.Json.Linq;
using Configuration.ServerApi.Dao;
using Configuration.ServerApi.Entity;
using Configuration.ServerApi.Enum;
using Configuration.ServerApi.Param;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Service.Impl
{
    /// <summary>
    /// RecordService
    /// </summary>
    public class RecordService : IRecordService
    {
        private readonly IConfiguration Configuration;
        private readonly IHttpContextAccessor Accessor;
        private readonly IBisOperationRecordDao BisOperationRecordDao;
        private readonly IBisExperimentRecordDao BisExperimentRecordDao;
        private readonly IBisExperimentRunLogDao BisExperimentRunLogDao;
        private readonly IBisExperimentRunLogBallMillingDao BisExperimentRunLogBallMillingDao;
        private readonly IBisExperimentRunLogBallMillingTwoDao BisExperimentRunLogBallMillingTwoDao;
        private readonly IBisExperimentRunLogBottomFurnaceDao BisExperimentRunLogBottomFurnaceDao;
        private readonly IBisExperimentRunLogElectroChemistryTestDao BisExperimentRunLogElectroChemistryTestDao;
        private readonly IBisExperimentRunLogOvenDao BisExperimentRunLogOvenDao;
        private readonly IBisExperimentRunLogTubeFurnaceDao BisExperimentRunLogTubeFurnaceDao;
        private readonly IBisWarningRecordDao BisWarningRecordDao;
        private readonly IBisExpConfigBalanceDao BisExpConfigBalanceDao;
        private readonly IBisExpConfigBallMillingDao BisExpConfigBallMillingDao;
        private readonly IBisExpConfigBallMillingTwoDao BisExpConfigBallMillingTwoDao;
        private readonly IBisExpConfigBottomFurnaceDao BisExpConfigBottomFurnaceDao;
        private readonly IBisExpConfigCapperDao BisExpConfigCapperDao;
        private readonly IBisExpConfigCapperTwoDao BisExpConfigCapperTwoDao;
        private readonly IBisExpConfigCrucibleConversionDao BisExpConfigCrucibleConversionDao;
        private readonly IBisExpConfigCrusherDao BisExpConfigCrusherDao;
        private readonly IBisExpConfigElectroChemistryTestingDao BisExpConfigElectroChemistryTestingDao;
        private readonly IBisExpConfigFlourBlendingDao BisExpConfigFlourBlendingDao;
        private readonly IBisExpConfigMaterialPositionTableDao BisExpConfigMaterialPositionTableDao;
        private readonly IBisExpConfigNodeDao BisExpConfigNodeDao;
        private readonly IBisExpConfigOvenDao BisExpConfigOvenDao;
        private readonly IBisExpConfigPackagingDao BisExpConfigPackagingDao;
        private readonly IBisExpConfigPipetteDistributionDao BisExpConfigPipetteDistributionDao;
        private readonly IBisExpConfigScrapingDao BisExpConfigScrapingDao;
        private readonly IBisExpConfigSolidLiquidTestingDao BisExpConfigSolidLiquidTestingDao;
        private readonly IBisExpConfigTabletPressDao BisExpConfigTabletPressDao;
        private readonly IBisExpConfigTubeFurnaceDao BisExpConfigTubeFurnaceDao;
        private readonly IBisExpConfigUltrasonicCleaningMachineDao BisExpConfigUltrasonicCleaningMachineDao;
        private readonly IBisExpConfigXRDTestDao BisExpConfigXRDTestDao;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="accessor"></param>
        /// <param name="bisOperationRecordDao"></param>
        /// <param name="bisExperimentRecordDao"></param>
        /// <param name="bisExperimentRunLogDao"></param>
        /// <param name="bisExperimentRunLogBallMillingDao"></param>
        /// <param name="bisExperimentRunLogBallMillingTwoDao"></param>
        /// <param name="bisExperimentRunLogBottomFurnaceDao"></param>
        /// <param name="bisExperimentRunLogElectroChemistryTestDao"></param>
        /// <param name="bisExperimentRunLogOvenDao"></param>
        /// <param name="bisExperimentRunLogTubeFurnaceDao"></param>
        /// <param name="bisWarningRecordDao"></param>
        /// <param name="bisExpConfigBalanceDao"></param>
        /// <param name="bisExpConfigBallMillingDao"></param>
        /// <param name="bisExpConfigBallMillingTwoDao"></param>
        /// <param name="bisExpConfigBottomFurnaceDao"></param>
        /// <param name="bisExpConfigCapperDao"></param>
        /// <param name="bisExpConfigCapperTwoDao"></param>
        /// <param name="bisExpConfigCrucibleConversionDao"></param>
        /// <param name="bisExpConfigCrusherDao"></param>
        /// <param name="bisExpConfigElectroChemistryTestingDao"></param>
        /// <param name="bisExpConfigFlourBlendingDao"></param>
        /// <param name="bisExpConfigMaterialPositionTableDao"></param>
        /// <param name="bisExpConfigNodeDao"></param>
        /// <param name="bisExpConfigOvenDao"></param>
        /// <param name="bisExpConfigPackagingDao"></param>
        /// <param name="bisExpConfigPipetteDistributionDao"></param>
        /// <param name="bisExpConfigScrapingDao"></param>
        /// <param name="bisExpConfigSolidLiquidTestingDao"></param>
        /// <param name="bisExpConfigTabletPressDao"></param>
        /// <param name="bisExpConfigTubeFurnaceDao"></param>
        /// <param name="bisExpConfigUltrasonicCleaningMachineDao"></param>
        /// <param name="bisExpConfigXRDTestDao"></param>
        public RecordService(IConfiguration configuration,
            IHttpContextAccessor accessor,
            IBisOperationRecordDao bisOperationRecordDao,
            IBisExperimentRecordDao bisExperimentRecordDao,
            IBisExperimentRunLogDao bisExperimentRunLogDao,
            IBisExperimentRunLogBallMillingDao bisExperimentRunLogBallMillingDao,
            IBisExperimentRunLogBallMillingTwoDao bisExperimentRunLogBallMillingTwoDao,
            IBisExperimentRunLogBottomFurnaceDao bisExperimentRunLogBottomFurnaceDao,
            IBisExperimentRunLogElectroChemistryTestDao bisExperimentRunLogElectroChemistryTestDao,
            IBisExperimentRunLogOvenDao bisExperimentRunLogOvenDao,
            IBisExperimentRunLogTubeFurnaceDao bisExperimentRunLogTubeFurnaceDao,
            IBisWarningRecordDao bisWarningRecordDao,
            IBisExpConfigBalanceDao bisExpConfigBalanceDao,
            IBisExpConfigBallMillingDao bisExpConfigBallMillingDao,
            IBisExpConfigBallMillingTwoDao bisExpConfigBallMillingTwoDao,
            IBisExpConfigBottomFurnaceDao bisExpConfigBottomFurnaceDao,
            IBisExpConfigCapperDao bisExpConfigCapperDao,
            IBisExpConfigCapperTwoDao bisExpConfigCapperTwoDao,
            IBisExpConfigCrucibleConversionDao bisExpConfigCrucibleConversionDao,
            IBisExpConfigCrusherDao bisExpConfigCrusherDao,
            IBisExpConfigElectroChemistryTestingDao bisExpConfigElectroChemistryTestingDao,
            IBisExpConfigFlourBlendingDao bisExpConfigFlourBlendingDao,
            IBisExpConfigMaterialPositionTableDao bisExpConfigMaterialPositionTableDao,
            IBisExpConfigNodeDao bisExpConfigNodeDao,
            IBisExpConfigOvenDao bisExpConfigOvenDao,
            IBisExpConfigPackagingDao bisExpConfigPackagingDao,
            IBisExpConfigPipetteDistributionDao bisExpConfigPipetteDistributionDao,
            IBisExpConfigScrapingDao bisExpConfigScrapingDao,
            IBisExpConfigSolidLiquidTestingDao bisExpConfigSolidLiquidTestingDao,
            IBisExpConfigTabletPressDao bisExpConfigTabletPressDao,
            IBisExpConfigTubeFurnaceDao bisExpConfigTubeFurnaceDao,
            IBisExpConfigUltrasonicCleaningMachineDao bisExpConfigUltrasonicCleaningMachineDao,
            IBisExpConfigXRDTestDao bisExpConfigXRDTestDao)
        {
            Configuration = configuration;
            Accessor = accessor;
            BisOperationRecordDao = bisOperationRecordDao;
            BisExperimentRecordDao = bisExperimentRecordDao;
            BisExperimentRunLogDao = bisExperimentRunLogDao;
            BisExperimentRunLogBallMillingDao = bisExperimentRunLogBallMillingDao;
            BisExperimentRunLogBallMillingTwoDao = bisExperimentRunLogBallMillingTwoDao;
            BisExperimentRunLogBottomFurnaceDao = bisExperimentRunLogBottomFurnaceDao;
            BisExperimentRunLogElectroChemistryTestDao = bisExperimentRunLogElectroChemistryTestDao;
            BisExperimentRunLogOvenDao = bisExperimentRunLogOvenDao;
            BisExperimentRunLogTubeFurnaceDao = bisExperimentRunLogTubeFurnaceDao;
            BisWarningRecordDao = bisWarningRecordDao;
            BisExpConfigBalanceDao = bisExpConfigBalanceDao;
            BisExpConfigBallMillingDao = bisExpConfigBallMillingDao;
            BisExpConfigBallMillingTwoDao = bisExpConfigBallMillingTwoDao;
            BisExpConfigBottomFurnaceDao = bisExpConfigBottomFurnaceDao;
            BisExpConfigCapperDao = bisExpConfigCapperDao;
            BisExpConfigCapperTwoDao = bisExpConfigCapperTwoDao;
            BisExpConfigCrucibleConversionDao = bisExpConfigCrucibleConversionDao;
            BisExpConfigCrusherDao = bisExpConfigCrusherDao;
            BisExpConfigElectroChemistryTestingDao = bisExpConfigElectroChemistryTestingDao;
            BisExpConfigFlourBlendingDao = bisExpConfigFlourBlendingDao;
            BisExpConfigMaterialPositionTableDao = bisExpConfigMaterialPositionTableDao;
            BisExpConfigNodeDao = bisExpConfigNodeDao;
            BisExpConfigOvenDao = bisExpConfigOvenDao;
            BisExpConfigPackagingDao = bisExpConfigPackagingDao;
            BisExpConfigPipetteDistributionDao = bisExpConfigPipetteDistributionDao;
            BisExpConfigScrapingDao = bisExpConfigScrapingDao;
            BisExpConfigSolidLiquidTestingDao = bisExpConfigSolidLiquidTestingDao;
            BisExpConfigTabletPressDao = bisExpConfigTabletPressDao;
            BisExpConfigTubeFurnaceDao = bisExpConfigTubeFurnaceDao;
            BisExpConfigUltrasonicCleaningMachineDao = bisExpConfigUltrasonicCleaningMachineDao;
            BisExpConfigXRDTestDao = bisExpConfigXRDTestDao;
        }

        #endregion 构造函数

        #region 获取操作记录列表

        /// <summary>
        /// 获取操作记录列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> OperationRecordList(SearchModel param)
        {
            Console.WriteLine("\n获取操作记录列表：OperationRecordList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_operation_record, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"Name：{param.Name}");
            if (!string.IsNullOrEmpty(param.Name))
            {
                expression = expression.And(w => w.CreateUserName.Contains(param.Name));
            }

            Console.WriteLine($"Content：{param.Content}");
            if (!string.IsNullOrEmpty(param.Content))
            {
                expression = expression.And(w => w.Content.Contains(param.Content));
            }

            dynamic result = null;
            if (param.Page != null && param.Limit != null)
            {
                result = await BisOperationRecordDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisOperationRecordDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }
            var count = await BisOperationRecordDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取操作记录详情

        /// <summary>
        /// 获取操作记录详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> OperationRecordDetail(SearchModel param)
        {
            Console.WriteLine("\n获取操作记录详情：OperationRecordDetail");

            #region 参数校验

            Console.WriteLine($"Id：{param.Id}");
            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = await BisOperationRecordDao.QuerySingle(w => w.Del_Flag == 0 && w.Id.Equals(param.Id))
            });
        }

        #endregion

        #region 提交操作记录信息

        /// <summary>
        /// 提交操作记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> SubmitOperationRecord(UpdateModel param)
        {
            Console.WriteLine("\n提交操作记录信息：SubmitOperationRecord");

            #region 参数、数据校验

            Console.WriteLine($"Content：{param.Content}");

            if (string.IsNullOrEmpty(param.Content))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion 

            #region 获取所需数据

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            string orgId = string.Empty;
            string orgName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                orgName = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            #endregion

            #region 数据提交

            DateTime now = DateTime.Now;
            Guid guid = Guid.NewGuid();
            string newId = guid.ToString().ToUpper();

            int result = await BisOperationRecordDao.Insert(new bis_operation_record()
            {
                Id = newId,
                Content = param.Content,
                OrgGuid = orgId,
                OrgName = orgName,
                CreateUser = userId,
                CreateUserName = userName,
                CreateTime = now,
                UpdateUser = userId,
                UpdateUserName = userName,
                UpdateTime = now,
                Del_Flag = 0
            });

            return new JsonResult(new ResultModel
            {
                Msg = "新增成功"
            });

            #endregion 数据提交
        }

        #endregion

        #region 批量删除操作记录信息

        /// <summary>
        /// 批量删除操作记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> DelOperationRecord(UpdateModel param)
        {
            Console.WriteLine("\n批量删除操作记录信息：DelOperationRecord");

            #region 参数效验

            Console.WriteLine($"Id：{param.Id}");

            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;
            string[] idArray = param.Id.Split(',');

            int result = 0;
            foreach (var item in idArray)
            {
                Console.WriteLine(item);
                if (!item.Equals(userId))
                {
                    result += await BisOperationRecordDao.Update(u => new bis_operation_record
                    {
                        Del_Flag = 1,
                        UpdateUser = userId,
                        UpdateUserName = userName,
                        UpdateTime = now
                    }, w => w.Id.Equals(item));
                }
            }

            return new JsonResult(new ResultModel
            {
                Msg = "删除成功",
                Data = result
            });
        }

        #endregion

        #region 获取实验任务队列数据

        /// <summary>
        /// 获取实验任务队列数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentTaskQueueList(SearchModel param)
        {
            Console.WriteLine("\n获取实验任务队列数据：ExperimentTaskQueueList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_record, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"Name：{param.Name}");
            if (!string.IsNullOrEmpty(param.Name))
            {
                expression = expression.And(w => w.Name.Contains(param.Name));
            }

            Console.WriteLine($"Number：{param.Number}");
            if (!string.IsNullOrEmpty(param.Number))
            {
                expression = expression.And(w => w.Number.Contains(param.Number));
            }

            Console.WriteLine($"Status：{param.Status}");
            if (!string.IsNullOrEmpty(param.Status))
            {
                string[] conditions = param.Status.Split(',');
                Expression<Func<bis_experiment_record, bool>> expressionSub = w => w.Status.Equals(conditions.GetValue(0).ToString());
                expressionSub = expressionSub.And(w => w.Del_Flag == 0);
                for (int i = 1; i < conditions.Length; i++)
                {
                    var statusTmp = conditions.GetValue(i).ToString();
                    expressionSub = expressionSub.Or(w => w.Status.Equals(statusTmp));
                }
                expression = expression.And(expressionSub);
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_record> result = new List<bis_experiment_record>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRecordDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.Sort, OrderByType.Asc);
            }
            else
            {
                result = await BisExperimentRecordDao.QueryByWhere(expression, o => o.Sort, OrderByType.Asc);
            }

            if (result.Count > 0)
            {
                // 处理每行数据的指定字段内容
                Parallel.ForEach(result, (item) =>
                {
                    item.FlowPathConfig = "";
                    item.AssemblyConfig = "";
                });
            }

            var count = await BisExperimentRecordDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取实验记录列表

        /// <summary>
        /// 获取实验记录列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRecordList(SearchModel param)
        {
            Console.WriteLine("\n获取实验记录列表：ExperimentRecordList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_record, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"Name：{param.Name}");
            if (!string.IsNullOrEmpty(param.Name))
            {
                expression = expression.And(w => w.Name.Contains(param.Name));
            }

            Console.WriteLine($"Number：{param.Number}");
            if (!string.IsNullOrEmpty(param.Number))
            {
                expression = expression.And(w => w.Number.Contains(param.Number));
            }

            Console.WriteLine($"Status：{param.Status}");
            if (!string.IsNullOrEmpty(param.Status))
            {
                string[] conditions = param.Status.Split(',');
                Expression<Func<bis_experiment_record, bool>> expressionSub = w => w.Status.Equals(conditions.GetValue(0).ToString());
                expressionSub = expressionSub.And(w => w.Del_Flag == 0);
                for (int i = 1; i < conditions.Length; i++)
                {
                    var statusTmp = conditions.GetValue(i).ToString();
                    expressionSub = expressionSub.Or(w => w.Status.Equals(statusTmp));
                }
                expression = expression.And(expressionSub);
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            Console.WriteLine($"IsCreateTimeAsc：{param.IsCreateTimeAsc}");
            List<bis_experiment_record> result = new List<bis_experiment_record>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRecordDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, param.IsCreateTimeAsc == "0" ? OrderByType.Desc : OrderByType.Asc);
            }
            else
            {
                result = await BisExperimentRecordDao.QueryByWhere(expression, o => o.CreateTime, param.IsCreateTimeAsc == "0" ? OrderByType.Desc : OrderByType.Asc);
            }

            if (result.Count > 0)
            {
                // 处理每行数据的指定字段内容
                Parallel.ForEach(result, (item) =>
                {
                    item.FlowPathConfig = "";
                    item.AssemblyConfig = "";
                });
            }

            var count = await BisExperimentRecordDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取实验记录详情

        /// <summary>
        /// 获取实验记录详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRecordDetail(SearchModel param)
        {
            Console.WriteLine("\n获取实验记录详情：ExperimentRecordDetail");

            #region 参数校验

            Console.WriteLine($"Id：{param.Id}");
            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            // 获取详情数据
            var result = await BisExperimentRecordDao.QuerySingle(w => w.Del_Flag == 0 && w.Id.Equals(param.Id));

            #region 获取配置数据

            Random rd = new Random();
            List<NodeConfigModel> NodeConfigData = new List<NodeConfigModel>();
            List<TubeFurnaceModel> models = new List<TubeFurnaceModel>();
            List<OvenModel> ovenModels = new List<OvenModel>();

            // 开盖机
            var Config_Capper = await BisExpConfigCapperDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Capper != null && Config_Capper.Count > 0)
            {
                Config_Capper.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Capper,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 开盖机2
            var Config_Capper_Two = await BisExpConfigCapperTwoDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Capper_Two != null && Config_Capper_Two.Count > 0)
            {
                Config_Capper_Two.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Capper2,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 物料定位台
            var Config_MaterialPositionTable = await BisExpConfigMaterialPositionTableDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_MaterialPositionTable != null && Config_MaterialPositionTable.Count > 0)
            {
                Config_MaterialPositionTable.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.MaterialPositioningTable,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 超声波清洗机
            var Config_UltrasonicCleaningMachine = await BisExpConfigUltrasonicCleaningMachineDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_UltrasonicCleaningMachine != null && Config_UltrasonicCleaningMachine.Count > 0)
            {
                Config_UltrasonicCleaningMachine.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.UltrasonicCleaningMachine,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 精密天平
            var Config_balance = await BisExpConfigBalanceDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_balance != null && Config_balance.Count > 0)
            {
                Config_balance.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.PrecisionBalance,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 高通量配粉系统
            var Config_FlourBlending = await BisExpConfigFlourBlendingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_FlourBlending != null && Config_FlourBlending.Count > 0)
            {
                Config_FlourBlending.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.FlourBlending,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 移液配比系统
            var Config_PipetteDistribution = await BisExpConfigPipetteDistributionDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_PipetteDistribution != null && Config_PipetteDistribution.Count > 0)
            {
                Config_PipetteDistribution.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.PipetteDistribution,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 球磨机1
            var Config_BallMilling = await BisExpConfigBallMillingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_BallMilling != null && Config_BallMilling.Count > 0)
            {
                Config_BallMilling.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.BallMilling,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 球磨机2
            var Config_BallMilling_Two = await BisExpConfigBallMillingTwoDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_BallMilling_Two != null && Config_BallMilling_Two.Count > 0)
            {
                Config_BallMilling_Two.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.BallMilling2,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 颚式破碎机
            var Config_Crusher = await BisExpConfigCrusherDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Crusher != null && Config_Crusher.Count > 0)
            {
                Config_Crusher.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Crusher,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 陶瓷压片机
            var Config_TabletPress = await BisExpConfigTabletPressDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_TabletPress != null && Config_TabletPress.Count > 0)
            {
                Config_TabletPress.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.TabletPress,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 刷料机
            var Config_Scraping = await BisExpConfigScrapingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Scraping != null && Config_Scraping.Count > 0)
            {
                Config_Scraping.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Scraping,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 坩埚转换位
            var Config_CrucibleConversion = await BisExpConfigCrucibleConversionDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_CrucibleConversion != null && Config_CrucibleConversion.Count > 0)
            {
                Config_CrucibleConversion.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.CrucibleConversion,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 自动化电池封装机
            var Config_Packaging = await BisExpConfigPackagingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Packaging != null && Config_Packaging.Count > 0)
            {
                Config_Packaging.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Packaging,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 管式炉
            var Config_TubeFurnace = await BisExpConfigTubeFurnaceDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_TubeFurnace != null && Config_TubeFurnace.Count > 0)
            {
                Config_TubeFurnace.ForEach(item =>
                {
                    #region 添加节点配置数据

                    models = new List<TubeFurnaceModel>
                    {
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_1, Time = item.Time_1 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_2, Time = item.Time_2 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_3, Time = item.Time_3 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_4, Time = item.Time_4 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_5, Time = item.Time_5 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_6, Time = item.Time_6 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_7, Time = item.Time_7 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_8, Time = item.Time_8 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_9, Time = item.Time_9 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_10, Time = item.Time_10 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_11, Time = item.Time_11 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_12, Time = item.Time_12 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_13, Time = item.Time_13 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_14, Time = item.Time_14 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_15, Time = item.Time_15 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_16, Time = item.Time_16 },
                    };

                    #endregion

                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.TubeFurnace,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = new { workingHours = item.WorkingHours, param = models }
                    });
                });
            }

            // 下装炉
            var Config_BottomFurnace = await BisExpConfigBottomFurnaceDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_BottomFurnace != null && Config_BottomFurnace.Count > 0)
            {
                Config_BottomFurnace.ForEach(item =>
                {
                    #region 添加节点配置数据

                    models = new List<TubeFurnaceModel>
                    {
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_1, Time = item.Time_1 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_2, Time = item.Time_2 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_3, Time = item.Time_3 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_4, Time = item.Time_4 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_5, Time = item.Time_5 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_6, Time = item.Time_6 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_7, Time = item.Time_7 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_8, Time = item.Time_8 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_9, Time = item.Time_9 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_10, Time = item.Time_10 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_11, Time = item.Time_11 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_12, Time = item.Time_12 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_13, Time = item.Time_13 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_14, Time = item.Time_14 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_15, Time = item.Time_15 },
                        new TubeFurnaceModel() { Key = $"{rd.Next(10000, 99999)}", Temperature = item.Temperature_16, Time = item.Time_16 },
                    };

                    #endregion

                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.BottomFurnace,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = new { workingHours = item.WorkingHours, param = models }
                    });
                });
            }

            // 固液测试平台
            var Config_SolidLiquidTesting = await BisExpConfigSolidLiquidTestingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_SolidLiquidTesting != null && Config_SolidLiquidTesting.Count > 0)
            {
                Config_SolidLiquidTesting.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.SolidLiquidTesting,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 电化学测试仪器
            var Config_ElectroChemistryTesting = await BisExpConfigElectroChemistryTestingDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_ElectroChemistryTesting != null && Config_ElectroChemistryTesting.Count > 0)
            {
                Config_ElectroChemistryTesting.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.ElectroChemistryTesting,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // XRD测试仪
            var Config_XRDTest = await BisExpConfigXRDTestDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_XRDTest != null && Config_XRDTest.Count > 0)
            {
                Config_XRDTest.ForEach(item =>
                {
                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.XRDDevice,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = item
                    });
                });
            }

            // 自动化烘干机
            var Config_Oven = await BisExpConfigOvenDao.QueryByWhere(w => w.Del_Flag == 0 && w.ExpId.Equals(param.Id));
            if (Config_Oven != null && Config_Oven.Count > 0)
            {
                Config_Oven.ForEach(item =>
                {
                    #region 添加节点配置数据

                    ovenModels = new List<OvenModel>
                    {
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_1, Temperature = item.Temperature_1, Speed = item.Time_1 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_2, Temperature = item.Temperature_2, Speed = item.Time_2 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_3, Temperature = item.Temperature_3, Speed = item.Time_3 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_4, Temperature = item.Temperature_4, Speed = item.Time_4 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_5, Temperature = item.Temperature_5, Speed = item.Time_5 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_6, Temperature = item.Temperature_6, Speed = item.Time_6 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_7, Temperature = item.Temperature_7, Speed = item.Time_7 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_8, Temperature = item.Temperature_8, Speed = item.Time_8 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_9, Temperature = item.Temperature_9, Speed = item.Time_9 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_10, Temperature = item.Temperature_10, Speed = item.Time_10 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_11, Temperature = item.Temperature_11, Speed = item.Time_11 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_12, Temperature = item.Temperature_12, Speed = item.Time_12 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_13, Temperature = item.Temperature_13, Speed = item.Time_13 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_14, Temperature = item.Temperature_14, Speed = item.Time_14 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_15, Temperature = item.Temperature_15, Speed = item.Time_15 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_16, Temperature = item.Temperature_16, Speed = item.Time_16 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_17, Temperature = item.Temperature_17, Speed = item.Time_17 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_18, Temperature = item.Temperature_18, Speed = item.Time_18 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_19, Temperature = item.Temperature_19, Speed = item.Time_19 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_20, Temperature = item.Temperature_20, Speed = item.Time_20 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_21, Temperature = item.Temperature_21, Speed = item.Time_21 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_22, Temperature = item.Temperature_22, Speed = item.Time_22 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_23, Temperature = item.Temperature_23, Speed = item.Time_23 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_24, Temperature = item.Temperature_24, Speed = item.Time_24 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_25, Temperature = item.Temperature_25, Speed = item.Time_25 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_26, Temperature = item.Temperature_26, Speed = item.Time_26 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_27, Temperature = item.Temperature_27, Speed = item.Time_27 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_28, Temperature = item.Temperature_28, Speed = item.Time_28 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_29, Temperature = item.Temperature_29, Speed = item.Time_29 },
                        new OvenModel() { Key = $"{rd.Next(10000, 99999)}", Time = item.Time_30, Temperature = item.Temperature_30, Speed = item.Time_30 },
                    };

                    #endregion

                    NodeConfigData.Add(new NodeConfigModel()
                    {
                        Id = item.NodeId,
                        Name = DeviceName.Oven,
                        WorkingHours = item.WorkingHours.ToString(),
                        Data = new { workingHours = item.WorkingHours, param = ovenModels }
                    });
                });
            }

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result,
                Data2 = NodeConfigData
            });
        }

        #endregion

        #region 提交实验记录信息

        /// <summary>
        /// 提交实验记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> SubmitExperimentRecord(UpdateModel param)
        {
            Console.WriteLine("\n提交实验记录信息：SubmitExperimentRecord");

            #region 参数、数据校验

            Console.WriteLine($"ExpRecordData：{param.ExpRecordData}");
            Console.WriteLine($"NodeConfigData：{param.NodeConfigData}");
            Console.WriteLine($"ExpConfigNodeData：{param.ExpConfigNodeData}");

            if (param.ExpRecordData == null ||
                param.ExpConfigNodeData == null)
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion 

            #region 获取所需数据

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            string orgId = string.Empty;
            string orgName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                orgName = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            #endregion

            #region 数据提交

            JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();

            DateTime now = DateTime.Now;
            Guid guid = Guid.NewGuid();
            string newId = guid.ToString().ToUpper();
            int result = 0;

            result += await BisExperimentRecordDao.Insert(new bis_experiment_record()
            {
                Id = newId,
                Name = param.ExpRecordData.Name,
                Number = param.ExpRecordData.Number,
                Status = param.ExpRecordData.Status,
                ExpectedWorkingHours = param.ExpRecordData.ExpectedWorkingHours,
                Sort = param.ExpRecordData.Sort,
                ExpStartTime = param.ExpRecordData.ExpStartTime,
                ExpEndTime = param.ExpRecordData.ExpEndTime,
                FlowPathConfig = param.ExpRecordData.FlowPathConfig,
                AssemblyConfig = param.ExpRecordData.AssemblyConfig,
                Remark = param.ExpRecordData.Remark,
                OrgGuid = orgId,
                OrgName = orgName,
                CreateUser = userId,
                CreateUserName = userName,
                CreateTime = now,
                UpdateUser = userId,
                UpdateUserName = userName,
                UpdateTime = now,
                Del_Flag = 0
            });

            if (param.ExpConfigNodeData != null)
            {
                // 按时间进行排序
                param.ExpConfigNodeData = param.ExpConfigNodeData.OrderBy(o => o.CreateTime).ToList();

                // 节点排序号
                int SortValue = 1;

                param.ExpConfigNodeData.ForEach(item =>
                {
                    item.Id = Guid.NewGuid().ToString().ToUpper();
                    item.ExpId = newId;
                    item.ExpName = param.ExpRecordData.Name;
                    item.Sort = SortValue;
                    item.Remark = "";
                    item.CreateUser = userId;
                    item.CreateUserName = userName;
                    item.CreateTime = now;
                    item.UpdateUser = userId;
                    item.UpdateUserName = userName;
                    item.UpdateTime = now;
                    item.Del_Flag = 0;

                    SortValue++;    // 排序号值加一
                });
                result += await BisExpConfigNodeDao.InsertMany(param.ExpConfigNodeData);
            }

            #region 创建关联节点配置数据

            if (param.NodeConfigData != null)
            {
                param.NodeConfigData.ForEach(async item =>
                {
                    switch (item.Name)
                    {
                        case DeviceName.Capper:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_capper>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigCapperDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.Capper2:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_capper_two>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigCapperTwoDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.MaterialPositioningTable:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_materialpositiontable>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigMaterialPositionTableDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.UltrasonicCleaningMachine:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_ultrasoniccleaningmachine>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigUltrasonicCleaningMachineDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.PrecisionBalance:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_balance>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigBalanceDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.FlourBlending:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_flourblending>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigFlourBlendingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.PipetteDistribution:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_pipettedistribution>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigPipetteDistributionDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.BallMilling:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_ballmilling>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigBallMillingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.BallMilling2:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_ballmilling_two>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigBallMillingTwoDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.Crusher:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_crusher>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigCrusherDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.TabletPress:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_tabletpress>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigTabletPressDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.Scraping:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_scraping>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigScrapingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.CrucibleConversion:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_crucibleconversion>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigCrucibleConversionDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.Packaging:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_packaging>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigPackagingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.TubeFurnace:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_tubefurnace>(item.Data.ToString());

                                JObject jo = JObject.Parse(item.Data.ToString());
                                var ParamData = JavaScriptSerializer.Deserialize<List<TubeFurnaceModel>>(jo["param"].ToString());
                                try
                                {
                                    SaveData.Temperature_1 = ParamData[0].Temperature;
                                    SaveData.Time_1 = ParamData[0].Time;

                                    SaveData.Temperature_2 = ParamData[1].Temperature;
                                    SaveData.Time_2 = ParamData[1].Time;

                                    SaveData.Temperature_3 = ParamData[2].Temperature;
                                    SaveData.Time_3 = ParamData[2].Time;

                                    SaveData.Temperature_4 = ParamData[3].Temperature;
                                    SaveData.Time_4 = ParamData[3].Time;

                                    SaveData.Temperature_5 = ParamData[4].Temperature;
                                    SaveData.Time_5 = ParamData[4].Time;

                                    SaveData.Temperature_6 = ParamData[5].Temperature;
                                    SaveData.Time_6 = ParamData[5].Time;

                                    SaveData.Temperature_7 = ParamData[6].Temperature;
                                    SaveData.Time_7 = ParamData[6].Time;

                                    SaveData.Temperature_8 = ParamData[7].Temperature;
                                    SaveData.Time_8 = ParamData[7].Time;

                                    SaveData.Temperature_9 = ParamData[8].Temperature;
                                    SaveData.Time_9 = ParamData[8].Time;

                                    SaveData.Temperature_10 = ParamData[9].Temperature;
                                    SaveData.Time_10 = ParamData[9].Time;

                                    SaveData.Temperature_11 = ParamData[10].Temperature;
                                    SaveData.Time_11 = ParamData[10].Time;

                                    SaveData.Temperature_12 = ParamData[11].Temperature;
                                    SaveData.Time_12 = ParamData[11].Time;

                                    SaveData.Temperature_13 = ParamData[12].Temperature;
                                    SaveData.Time_13 = ParamData[12].Time;

                                    SaveData.Temperature_14 = ParamData[13].Temperature;
                                    SaveData.Time_14 = ParamData[13].Time;

                                    SaveData.Temperature_15 = ParamData[14].Temperature;
                                    SaveData.Time_15 = ParamData[14].Time;

                                    SaveData.Temperature_16 = ParamData[15].Temperature;
                                    SaveData.Time_16 = ParamData[15].Time;
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine($"已超出索引, 取消读取 {ex.Message}");
                                }

                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigTubeFurnaceDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.BottomFurnace:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_bottomfurnace>(item.Data.ToString());

                                JObject jo = JObject.Parse(item.Data.ToString());
                                var ParamData = JavaScriptSerializer.Deserialize<List<TubeFurnaceModel>>(jo["param"].ToString());
                                try
                                {
                                    SaveData.Temperature_1 = ParamData[0].Temperature;
                                    SaveData.Time_1 = ParamData[0].Time;

                                    SaveData.Temperature_2 = ParamData[1].Temperature;
                                    SaveData.Time_2 = ParamData[1].Time;

                                    SaveData.Temperature_3 = ParamData[2].Temperature;
                                    SaveData.Time_3 = ParamData[2].Time;

                                    SaveData.Temperature_4 = ParamData[3].Temperature;
                                    SaveData.Time_4 = ParamData[3].Time;

                                    SaveData.Temperature_5 = ParamData[4].Temperature;
                                    SaveData.Time_5 = ParamData[4].Time;

                                    SaveData.Temperature_6 = ParamData[5].Temperature;
                                    SaveData.Time_6 = ParamData[5].Time;

                                    SaveData.Temperature_7 = ParamData[6].Temperature;
                                    SaveData.Time_7 = ParamData[6].Time;

                                    SaveData.Temperature_8 = ParamData[7].Temperature;
                                    SaveData.Time_8 = ParamData[7].Time;

                                    SaveData.Temperature_9 = ParamData[8].Temperature;
                                    SaveData.Time_9 = ParamData[8].Time;

                                    SaveData.Temperature_10 = ParamData[9].Temperature;
                                    SaveData.Time_10 = ParamData[9].Time;

                                    SaveData.Temperature_11 = ParamData[10].Temperature;
                                    SaveData.Time_11 = ParamData[10].Time;

                                    SaveData.Temperature_12 = ParamData[11].Temperature;
                                    SaveData.Time_12 = ParamData[11].Time;

                                    SaveData.Temperature_13 = ParamData[12].Temperature;
                                    SaveData.Time_13 = ParamData[12].Time;

                                    SaveData.Temperature_14 = ParamData[13].Temperature;
                                    SaveData.Time_14 = ParamData[13].Time;

                                    SaveData.Temperature_15 = ParamData[14].Temperature;
                                    SaveData.Time_15 = ParamData[14].Time;

                                    SaveData.Temperature_16 = ParamData[15].Temperature;
                                    SaveData.Time_16 = ParamData[15].Time;
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine($"已超出索引, 取消读取 {ex.Message}");
                                }

                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigBottomFurnaceDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.SolidLiquidTesting:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_solidliquidtesting>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigSolidLiquidTestingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.ElectroChemistryTesting:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(item.Data.ToString());
                                try
                                {
                                    JObject jo = JObject.Parse(item.Data.ToString());
                                    bis_expconfig_electrochemistrytesting ConfigData = new bis_expconfig_electrochemistrytesting();
                                    switch (SaveData.SelExpId)
                                    {
                                        // 实验配置-0 开路电位(电分析)
                                        case "0":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_kldw"].ToString());
                                                SaveData.TimePerPoint = ConfigData.TimePerPoint;
                                                SaveData.ContinueTime = ConfigData.ContinueTime;
                                            }
                                            break;
                                        // 实验配置-1 线性扫描伏安法(LSV)
                                        case "1":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_xxsmfaf"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.ScanRate = ConfigData.ScanRate;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-2 循环伏安法
                                        case "2":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_xhfaf"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.ScanRate = ConfigData.ScanRate;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-3 循环伏安法(多循环)
                                        case "3":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_xhfafdxh"].ToString());
                                                SaveData.IsUseInitialPotential = ConfigData.IsUseInitialPotential;
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.TopPotential1 = ConfigData.TopPotential1;
                                                SaveData.TopPotential1VSType = ConfigData.TopPotential1VSType;
                                                SaveData.TopPotential2 = ConfigData.TopPotential2;
                                                SaveData.TopPotential2VSType = ConfigData.TopPotential2VSType;
                                                SaveData.IsUseFinallyPotential = ConfigData.IsUseFinallyPotential;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.ScanRate = ConfigData.ScanRate;
                                                SaveData.CycleCount = ConfigData.CycleCount;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-4 恒电位
                                        case "4":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_hdw"].ToString());
                                                SaveData.TimePerPoint = ConfigData.TimePerPoint;
                                                SaveData.ContinueTime = ConfigData.ContinueTime;
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-5 恒电流
                                        case "5":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_hdl"].ToString());
                                                SaveData.TimePerPoint = ConfigData.TimePerPoint;
                                                SaveData.ContinueTime = ConfigData.ContinueTime;
                                                SaveData.Current = ConfigData.Current;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-6 交流阻抗(电压)
                                        case "6":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_jlzkdy"].ToString());
                                                SaveData.IsVolEIS = ConfigData.IsVolEIS;
                                                SaveData.StartFreq = ConfigData.StartFreq;
                                                SaveData.EndFreq = ConfigData.EndFreq;
                                                SaveData.Amplitude = ConfigData.Amplitude;
                                                SaveData.IntervalType = ConfigData.IntervalType;
                                                SaveData.PointCount = ConfigData.PointCount;
                                                SaveData.Voltage = ConfigData.Voltage;
                                                SaveData.VoltageVSType = ConfigData.VoltageVSType;
                                            }
                                            break;
                                        // 实验配置-7 交流阻抗(电流)
                                        case "7":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_jlzkdl"].ToString());
                                                SaveData.IsVolEIS = ConfigData.IsVolEIS;
                                                SaveData.StartFreq = ConfigData.StartFreq;
                                                SaveData.EndFreq = ConfigData.EndFreq;
                                                SaveData.Amplitude = ConfigData.Amplitude;
                                                SaveData.IntervalType = ConfigData.IntervalType;
                                                SaveData.PointCount = ConfigData.PointCount;
                                                SaveData.Voltage = ConfigData.Voltage;
                                            }
                                            break;
                                        // 实验配置-8 阶梯循环伏安法
                                        case "8":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_jtxhfaf"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.TopPotential1 = ConfigData.TopPotential1;
                                                SaveData.TopPotential1VSType = ConfigData.TopPotential1VSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.StepHeight = ConfigData.StepHeight;
                                                SaveData.StepTime = ConfigData.StepTime;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-9 阶梯循环伏安法(多循环)
                                        case "9":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_jtxhfafdxh"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.TopPotential1 = ConfigData.TopPotential1;
                                                SaveData.TopPotential1VSType = ConfigData.TopPotential1VSType;
                                                SaveData.TopPotential2 = ConfigData.TopPotential2;
                                                SaveData.TopPotential2VSType = ConfigData.TopPotential2VSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.StepHeight = ConfigData.StepHeight;
                                                SaveData.StepTime = ConfigData.StepTime;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-10 阶梯线性扫描伏安法(SLSV)
                                        case "10":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_jtxxsmfafslsv"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.StepHeight = ConfigData.StepHeight;
                                                SaveData.StepTime = ConfigData.StepTime;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                        // 实验配置-11 Tafel
                                        case "11":
                                            {
                                                ConfigData = JavaScriptSerializer.Deserialize<bis_expconfig_electrochemistrytesting>(jo["expconfig_tafel"].ToString());
                                                SaveData.InitialPotential = ConfigData.InitialPotential;
                                                SaveData.InitialPotentialVSType = ConfigData.InitialPotentialVSType;
                                                SaveData.FinallyPotential = ConfigData.FinallyPotential;
                                                SaveData.FinallyPotentialVSType = ConfigData.FinallyPotentialVSType;
                                                SaveData.StepHeight = ConfigData.StepHeight;
                                                SaveData.StepTime = ConfigData.StepTime;
                                                SaveData.IsVoltageRandAuto = ConfigData.IsVoltageRandAuto;
                                                SaveData.VoltageRand = ConfigData.VoltageRand;
                                                SaveData.IsCurrentRandAuto = ConfigData.IsCurrentRandAuto;
                                                SaveData.CurrentRand = ConfigData.CurrentRand;
                                            }
                                            break;
                                    }
                                }
                                catch
                                {
                                    // 发生异常可能为从实验模板中直接提交实验, 无需按照此方式进行处理
                                }

                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigElectroChemistryTestingDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.XRDDevice:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_xrdtest>(item.Data.ToString());
                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigXRDTestDao.Insert(SaveData);
                            }
                            break;
                        case DeviceName.Oven:
                            {
                                var SaveData = JavaScriptSerializer.Deserialize<bis_expconfig_oven>(item.Data.ToString());

                                JObject jo = JObject.Parse(item.Data.ToString());
                                var ParamData = JavaScriptSerializer.Deserialize<List<OvenModel>>(jo["param"].ToString());
                                try
                                {
                                    SaveData.Time_1 = ParamData[0].Time;
                                    SaveData.Temperature_1 = ParamData[0].Temperature;
                                    SaveData.Speed_1 = ParamData[0].Speed;

                                    SaveData.Time_2 = ParamData[1].Time;
                                    SaveData.Temperature_2 = ParamData[1].Temperature;
                                    SaveData.Speed_2 = ParamData[1].Speed;

                                    SaveData.Time_3 = ParamData[2].Time;
                                    SaveData.Temperature_3 = ParamData[2].Temperature;
                                    SaveData.Speed_3 = ParamData[2].Speed;

                                    SaveData.Time_4 = ParamData[3].Time;
                                    SaveData.Temperature_4 = ParamData[3].Temperature;
                                    SaveData.Speed_4 = ParamData[3].Speed;

                                    SaveData.Time_5 = ParamData[4].Time;
                                    SaveData.Temperature_5 = ParamData[4].Temperature;
                                    SaveData.Speed_5 = ParamData[4].Speed;

                                    SaveData.Time_6 = ParamData[5].Time;
                                    SaveData.Temperature_6 = ParamData[5].Temperature;
                                    SaveData.Speed_6 = ParamData[5].Speed;

                                    SaveData.Time_7 = ParamData[6].Time;
                                    SaveData.Temperature_7 = ParamData[6].Temperature;
                                    SaveData.Speed_7 = ParamData[6].Speed;

                                    SaveData.Time_8 = ParamData[7].Time;
                                    SaveData.Temperature_8 = ParamData[7].Temperature;
                                    SaveData.Speed_8 = ParamData[7].Speed;

                                    SaveData.Time_9 = ParamData[8].Time;
                                    SaveData.Temperature_9 = ParamData[8].Temperature;
                                    SaveData.Speed_9 = ParamData[8].Speed;

                                    SaveData.Time_10 = ParamData[9].Time;
                                    SaveData.Temperature_10 = ParamData[9].Temperature;
                                    SaveData.Speed_10 = ParamData[9].Speed;

                                    SaveData.Time_11 = ParamData[10].Time;
                                    SaveData.Temperature_11 = ParamData[10].Temperature;
                                    SaveData.Speed_11 = ParamData[10].Speed;

                                    SaveData.Time_12 = ParamData[11].Time;
                                    SaveData.Temperature_12 = ParamData[11].Temperature;
                                    SaveData.Speed_12 = ParamData[11].Speed;

                                    SaveData.Time_13 = ParamData[12].Time;
                                    SaveData.Temperature_13 = ParamData[12].Temperature;
                                    SaveData.Speed_13 = ParamData[12].Speed;

                                    SaveData.Time_14 = ParamData[13].Time;
                                    SaveData.Temperature_14 = ParamData[13].Temperature;
                                    SaveData.Speed_14 = ParamData[13].Speed;

                                    SaveData.Time_15 = ParamData[14].Time;
                                    SaveData.Temperature_15 = ParamData[14].Temperature;
                                    SaveData.Speed_15 = ParamData[14].Speed;

                                    SaveData.Time_16 = ParamData[15].Time;
                                    SaveData.Temperature_16 = ParamData[15].Temperature;
                                    SaveData.Speed_16 = ParamData[15].Speed;

                                    SaveData.Time_17 = ParamData[16].Time;
                                    SaveData.Temperature_17 = ParamData[16].Temperature;
                                    SaveData.Speed_17 = ParamData[16].Speed;

                                    SaveData.Time_18 = ParamData[17].Time;
                                    SaveData.Temperature_18 = ParamData[17].Temperature;
                                    SaveData.Speed_18 = ParamData[17].Speed;

                                    SaveData.Time_19 = ParamData[18].Time;
                                    SaveData.Temperature_19 = ParamData[18].Temperature;
                                    SaveData.Speed_19 = ParamData[18].Speed;

                                    SaveData.Time_20 = ParamData[19].Time;
                                    SaveData.Temperature_20 = ParamData[19].Temperature;
                                    SaveData.Speed_20 = ParamData[19].Speed;

                                    SaveData.Time_21 = ParamData[20].Time;
                                    SaveData.Temperature_21 = ParamData[20].Temperature;
                                    SaveData.Speed_21 = ParamData[20].Speed;

                                    SaveData.Time_22 = ParamData[21].Time;
                                    SaveData.Temperature_22 = ParamData[21].Temperature;
                                    SaveData.Speed_22 = ParamData[21].Speed;

                                    SaveData.Time_23 = ParamData[22].Time;
                                    SaveData.Temperature_23 = ParamData[22].Temperature;
                                    SaveData.Speed_23 = ParamData[22].Speed;

                                    SaveData.Time_24 = ParamData[23].Time;
                                    SaveData.Temperature_24 = ParamData[23].Temperature;
                                    SaveData.Speed_24 = ParamData[23].Speed;

                                    SaveData.Time_25 = ParamData[24].Time;
                                    SaveData.Temperature_25 = ParamData[24].Temperature;
                                    SaveData.Speed_25 = ParamData[24].Speed;

                                    SaveData.Time_26 = ParamData[25].Time;
                                    SaveData.Temperature_26 = ParamData[25].Temperature;
                                    SaveData.Speed_26 = ParamData[25].Speed;

                                    SaveData.Time_27 = ParamData[26].Time;
                                    SaveData.Temperature_27 = ParamData[26].Temperature;
                                    SaveData.Speed_27 = ParamData[26].Speed;

                                    SaveData.Time_28 = ParamData[27].Time;
                                    SaveData.Temperature_28 = ParamData[27].Temperature;
                                    SaveData.Speed_28 = ParamData[27].Speed;

                                    SaveData.Time_29 = ParamData[28].Time;
                                    SaveData.Temperature_29 = ParamData[28].Temperature;
                                    SaveData.Speed_29 = ParamData[28].Speed;

                                    SaveData.Time_30 = ParamData[29].Time;
                                    SaveData.Temperature_30 = ParamData[29].Temperature;
                                    SaveData.Speed_30 = ParamData[29].Speed;
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine($"已超出索引, 取消读取 {ex.Message}");
                                }

                                SaveData.Id = Guid.NewGuid().ToString().ToUpper();
                                SaveData.ExpId = newId;
                                SaveData.ExpName = param.ExpRecordData.Name;
                                SaveData.NodeId = item.Id;
                                SaveData.Sort = 1;
                                SaveData.Remark = "";
                                SaveData.CreateUser = userId;
                                SaveData.CreateUserName = userName;
                                SaveData.CreateTime = now;
                                SaveData.UpdateUser = userId;
                                SaveData.UpdateUserName = userName;
                                SaveData.UpdateTime = now;
                                SaveData.Del_Flag = 0;

                                //Console.WriteLine();
                                result += await BisExpConfigOvenDao.Insert(SaveData);
                            }
                            break;
                    }
                });
            }

            #endregion

            return new JsonResult(new ResultModel
            {
                Msg = "新增成功"
            });

            #endregion 数据提交
        }

        #endregion

        #region 批量删除实验记录信息

        /// <summary>
        /// 批量删除实验记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> DelExperimentRecord(UpdateModel param)
        {
            Console.WriteLine("\n批量删除实验记录信息：DelExperimentRecord");

            #region 参数效验

            Console.WriteLine($"Id：{param.Id}");

            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;
            string[] idArray = param.Id.Split(',');

            int result = 0;
            foreach (var item in idArray)
            {
                Console.WriteLine(item);
                result += await BisExperimentRecordDao.Update(u => new bis_experiment_record
                {
                    Del_Flag = 1,
                    UpdateUser = userId,
                    UpdateUserName = userName,
                    UpdateTime = now
                }, w => w.Id.Equals(item));
            }

            return new JsonResult(new ResultModel
            {
                Msg = "删除成功",
                Data = result
            });
        }

        #endregion

        #region 更新实验记录状态

        /// <summary>
        /// 更新实验记录状态
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> UpdateExperimentRecordStstus(UpdateModel param)
        {
            Console.WriteLine("\n更新实验记录状态：UpdateExperimentRecordStstus");

            #region 参数效验

            Console.WriteLine($"Id：{param.Id}");
            Console.WriteLine($"Status：{param.Status}");

            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;
            string[] idArray = param.Id.Split(',');

            int result = 0;
            foreach (var item in idArray)
            {
                Console.WriteLine(item);
                switch (param.Status)
                {
                    case "40":
                        {
                            result += await BisExperimentRecordDao.Update(u => new bis_experiment_record
                            {
                                Status = param.Status,
                                ExpEndTime = now,
                                UpdateUser = userId,
                                UpdateUserName = userName,
                                UpdateTime = now
                            }, w => w.Id.Equals(item));
                        }
                        break;
                    default:
                        {
                            result += await BisExperimentRecordDao.Update(u => new bis_experiment_record
                            {
                                Status = param.Status,
                                UpdateUser = userId,
                                UpdateUserName = userName,
                                UpdateTime = now
                            }, w => w.Id.Equals(item));
                        }
                        break;
                }
            }

            return new JsonResult(new ResultModel
            {
                Msg = "提交成功",
                Data = result
            });
        }

        #endregion

        #region 更新实验任务顺序

        /// <summary>
        /// 更新实验任务顺序
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> UpdateExperimentRecordSort(UpdateModel param)
        {
            await Task.Run(() => { Console.WriteLine("\n更新实验任务顺序：UpdateExperimentRecordSort"); });

            #region 参数效验

            Console.WriteLine($"SetValueData：{param.SetValueData}");

            if (param.SetValueData == null)
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;

            int result = 0;
            Parallel.ForEach(param.SetValueData, async item =>
            {
                result += await BisExperimentRecordDao.Update(u => new bis_experiment_record
                {
                    Sort = int.Parse(item.Value)
                }, w => w.Id.Equals(item.Id));
            });

            return new JsonResult(new ResultModel
            {
                Msg = "提交成功",
                Data = result
            });
        }

        #endregion

        #region 获取实验运行日志列表

        /// <summary>
        /// 获取实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogList(SearchModel param)
        {
            Console.WriteLine("\n获取实验运行日志列表：ExperimentRunLogList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog> result = new List<bis_experiment_runlog>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取球磨机1实验运行日志列表

        /// <summary>
        /// 获取球磨机1实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByBallMillingList(SearchModel param)
        {
            Console.WriteLine("\n获取球磨机1实验运行日志列表：ExperimentRunLogByBallMillingList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_ballmilling, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_ballmilling> result = new List<bis_experiment_runlog_ballmilling>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogBallMillingDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogBallMillingDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogBallMillingDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取球磨机2实验运行日志列表

        /// <summary>
        /// 获取球磨机2实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByBallMillingTwoList(SearchModel param)
        {
            Console.WriteLine("\n获取球磨机2实验运行日志列表：ExperimentRunLogByBallMillingTwoList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_ballmilling_two, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_ballmilling_two> result = new List<bis_experiment_runlog_ballmilling_two>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogBallMillingTwoDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogBallMillingTwoDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogBallMillingTwoDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取管式炉实验运行日志列表

        /// <summary>
        /// 获取管式炉实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByTubeFurnaceList(SearchModel param)
        {
            Console.WriteLine("\n获取管式炉实验运行日志列表：ExperimentRunLogByTubeFurnaceList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_tubefurnace, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_tubefurnace> result = new List<bis_experiment_runlog_tubefurnace>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogTubeFurnaceDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogTubeFurnaceDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogTubeFurnaceDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取下装炉实验运行日志列表

        /// <summary>
        /// 获取下装炉实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByBottomFurnaceList(SearchModel param)
        {
            Console.WriteLine("\n获取下装炉实验运行日志列表：ExperimentRunLogByBottomFurnaceList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_bottomfurnace, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_bottomfurnace> result = new List<bis_experiment_runlog_bottomfurnace>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogBottomFurnaceDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogBottomFurnaceDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogBottomFurnaceDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取自动化烘干机实验运行日志列表

        /// <summary>
        /// 获取自动化烘干机实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByOvenList(SearchModel param)
        {
            Console.WriteLine("\n获取自动化烘干机实验运行日志列表：ExperimentRunLogByOvenList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_oven, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_oven> result = new List<bis_experiment_runlog_oven>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogOvenDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogOvenDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogOvenDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取电化学测试仪器实验运行日志列表

        /// <summary>
        /// 获取电化学测试仪器实验运行日志列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogByElectroChemistryTestList(SearchModel param)
        {
            Console.WriteLine("\n获取电化学测试仪器实验运行日志列表：ExperimentRunLogByElectroChemistryTestList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_electrochemistrytest, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            Console.WriteLine($"StartTime：{param.StartTime}");
            Console.WriteLine($"EndTime：{param.EndTime}");
            if (!string.IsNullOrEmpty(param.StartTime) && !string.IsNullOrEmpty(param.EndTime))
            {
                DateTime formatStartTimeStr = DateTime.Parse($"{param.StartTime} 00:00:00");
                DateTime formatEndTimeStr = DateTime.Parse($"{param.EndTime} 23:59:59");

                expression = expression.And(w => w.CreateTime >= formatStartTimeStr && w.CreateTime <= formatEndTimeStr);
            }

            List<bis_experiment_runlog_electrochemistrytest> result = new List<bis_experiment_runlog_electrochemistrytest>();
            if (param.Page != null && param.Limit != null)
            {
                result = await BisExperimentRunLogElectroChemistryTestDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisExperimentRunLogElectroChemistryTestDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }

            var count = await BisExperimentRunLogElectroChemistryTestDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取球磨机1图表数据

        /// <summary>
        /// 获取球磨机1图表数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> EChartDataByBallMilling(SearchModel param)
        {
            Console.WriteLine("\n获取球磨机1图表数据：EChartDataByBallMilling");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_ballmilling, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            var resultData = await BisExperimentRunLogBallMillingDao.QueryByWhere(expression, o => o.CreateTime);

            #region 处理返回数据

            List<string> xAxisData = new List<string>();
            List<dynamic> seriesData = new List<dynamic>();

            resultData.ForEach(item =>
            {
                xAxisData.Add(item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                seriesData.Add(item.Speed);
            });

            var result = new
            {
                title = new
                {
                    text = "球磨机1 (Ballmilling 1)",
                    rotate = 270,
                    left = "left",
                },
                tooltip = new
                {
                    trigger = "axis",
                    axisPointer = new
                    {
                        type = "cross",
                        label = new
                        {
                            backgroundColor = "#6a7985"
                        }
                    }
                },
                toolbox = new
                {
                    feature = new
                    {
                        saveAsImage = new { }
                    }
                },
                grid = new
                {
                    left = "3%",
                    right = "4%",
                    bottom = "3%",
                    containLabel = true
                },
                xAxis = new List<dynamic>()
                {
                    new {
                        type = "category",
                        boundaryGap = false,
                        data = xAxisData
                    }
                },
                yAxis = new List<dynamic>()
                {
                    new { type = "value" }
                },
                series = new List<dynamic>()
                {
                    new {
                        name = "转速 (Speed)",
                        type = "line",
                        data = seriesData
                    }
                }
            };

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取球磨机2图表数据

        /// <summary>
        /// 获取球磨机2图表数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> EChartDataByBallMillingTwo(SearchModel param)
        {
            Console.WriteLine("\n获取球磨机2图表数据：EChartDataByBallMillingTwo");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_ballmilling_two, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            var resultData = await BisExperimentRunLogBallMillingTwoDao.QueryByWhere(expression, o => o.CreateTime);

            #region 处理返回数据

            List<string> xAxisData = new List<string>();
            List<dynamic> seriesData = new List<dynamic>();

            resultData.ForEach(item =>
            {
                xAxisData.Add(item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                seriesData.Add(item.Speed);
            });

            var result = new
            {
                title = new
                {
                    text = "球磨机2 (Ballmilling 2)",
                    rotate = 270,
                    left = "left",
                },
                tooltip = new
                {
                    trigger = "axis",
                    axisPointer = new
                    {
                        type = "cross",
                        label = new
                        {
                            backgroundColor = "#6a7985"
                        }
                    }
                },
                toolbox = new
                {
                    feature = new
                    {
                        saveAsImage = new { }
                    }
                },
                grid = new
                {
                    left = "3%",
                    right = "4%",
                    bottom = "3%",
                    containLabel = true
                },
                xAxis = new List<dynamic>()
                {
                    new {
                        type = "category",
                        boundaryGap = false,
                        data = xAxisData
                    }
                },
                yAxis = new List<dynamic>()
                {
                    new { type = "value" }
                },
                series = new List<dynamic>()
                {
                    new {
                        name = "转速 (Speed)",
                        type = "line",
                        data = seriesData
                    }
                }
            };

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取管式炉图表数据

        /// <summary>
        /// 获取管式炉图表数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> EChartDataByTubeFurnace(SearchModel param)
        {
            Console.WriteLine("\n获取管式炉图表数据：EChartDataByTubeFurnace");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_tubefurnace, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            var resultData = await BisExperimentRunLogTubeFurnaceDao.QueryByWhere(expression, o => o.CreateTime);

            #region 处理返回数据

            List<string> xAxisData = new List<string>();
            List<dynamic> RealityTempData = new List<dynamic>();
            List<dynamic> RealityIntakeFlowRateData = new List<dynamic>();
            List<dynamic> VacuumPressureValueData = new List<dynamic>();

            resultData.ForEach(item =>
            {
                xAxisData.Add(item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                RealityTempData.Add(item.RealityTemp);
                RealityIntakeFlowRateData.Add(item.RealityIntakeFlowRate);
                VacuumPressureValueData.Add(item.VacuumPressureValue);
            });

            var result = new
            {
                title = new
                {
                    text = "管式炉 (TubeFurnace)",
                    rotate = 270,
                    left = "left",
                },
                tooltip = new
                {
                    trigger = "axis",
                    axisPointer = new
                    {
                        type = "cross",
                        label = new
                        {
                            backgroundColor = "#6a7985"
                        }
                    }
                },
                toolbox = new
                {
                    feature = new
                    {
                        saveAsImage = new { }
                    }
                },
                grid = new
                {
                    left = "3%",
                    right = "4%",
                    bottom = "3%",
                    containLabel = true
                },
                xAxis = new List<dynamic>()
                {
                    new {
                        type = "category",
                        boundaryGap = false,
                        data = xAxisData
                    }
                },
                yAxis = new List<dynamic>()
                {
                    new { type = "value" }
                },
                series = new List<dynamic>()
                {
                    new {
                        name = "实际温度 (RealityTemp)",
                        type = "line",
                        data = RealityTempData
                    },
                    new {
                        name = "实际进气流量 (RealityIntakeFlowRate)",
                        type = "line",
                        data = RealityIntakeFlowRateData
                    },
                    new {
                        name = "真空压力值 (VacuumPressureValue)",
                        type = "line",
                        data = VacuumPressureValueData
                    }
                }
            };

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取下装炉图表数据

        /// <summary>
        /// 获取下装炉图表数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> EChartDataByBottomFurnace(SearchModel param)
        {
            Console.WriteLine("\n获取下装炉图表数据：EChartDataByBottomFurnace");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_bottomfurnace, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            var resultData = await BisExperimentRunLogBottomFurnaceDao.QueryByWhere(expression, o => o.CreateTime);

            #region 处理返回数据

            List<string> xAxisData = new List<string>();
            List<dynamic> SettingTempData = new List<dynamic>();
            List<dynamic> RealityTempData = new List<dynamic>();
            List<dynamic> MeasureSpeedData = new List<dynamic>();

            resultData.ForEach(item =>
            {
                xAxisData.Add(item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                SettingTempData.Add(item.SettingTemp);
                RealityTempData.Add(item.RealityTemp);
                MeasureSpeedData.Add(item.MeasureSpeed);
            });

            var result = new
            {
                title = new
                {
                    text = "下装炉 (BottomFurnace)",
                    rotate = 270,
                    left = "left",
                },
                tooltip = new
                {
                    trigger = "axis",
                    axisPointer = new
                    {
                        type = "cross",
                        label = new
                        {
                            backgroundColor = "#6a7985"
                        }
                    }
                },
                toolbox = new
                {
                    feature = new
                    {
                        saveAsImage = new { }
                    }
                },
                grid = new
                {
                    left = "3%",
                    right = "4%",
                    bottom = "3%",
                    containLabel = true
                },
                xAxis = new List<dynamic>()
                {
                    new {
                        type = "category",
                        boundaryGap = false,
                        data = xAxisData
                    }
                },
                yAxis = new List<dynamic>()
                {
                    new { type = "value" }
                },
                series = new List<dynamic>()
                {
                    new {
                        name = "设定温度 (SettingTemp)",
                        type = "line",
                        data = SettingTempData
                    },
                    new {
                        name = "实际温度 (RealityTemp)",
                        type = "line",
                        data = RealityTempData
                    },
                    new {
                        name = "测量转速 (MeasureSpeedData)",
                        type = "line",
                        data = MeasureSpeedData
                    }
                }
            };

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取自动化烘干机图表数据

        /// <summary>
        /// 获取自动化烘干机图表数据
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> EChartDataByOven(SearchModel param)
        {
            Console.WriteLine("\n获取自动化烘干机图表数据：EChartDataByOven");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_experiment_runlog_oven, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"ExpId：{param.ExpId}");
            if (!string.IsNullOrEmpty(param.ExpId))
            {
                expression = expression.And(w => w.ExpId.Contains(param.ExpId));
            }

            var resultData = await BisExperimentRunLogOvenDao.QueryByWhere(expression, o => o.CreateTime);

            #region 处理返回数据

            List<string> xAxisData = new List<string>();
            List<dynamic> MeasureTempData = new List<dynamic>();
            List<dynamic> MeasureSpeedData = new List<dynamic>();

            resultData.ForEach(item =>
            {
                xAxisData.Add(item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                MeasureTempData.Add(item.MeasureTemp);
                MeasureSpeedData.Add(item.MeasureSpeed);
            });

            var result = new
            {
                title = new
                {
                    text = "烘箱 (Oven)",
                    rotate = 270,
                    left = "left",
                },
                tooltip = new
                {
                    trigger = "axis",
                    axisPointer = new
                    {
                        type = "cross",
                        label = new
                        {
                            backgroundColor = "#6a7985"
                        }
                    }
                },
                toolbox = new
                {
                    feature = new
                    {
                        saveAsImage = new { }
                    }
                },
                grid = new
                {
                    left = "3%",
                    right = "4%",
                    bottom = "3%",
                    containLabel = true
                },
                xAxis = new List<dynamic>()
                {
                    new {
                        type = "category",
                        boundaryGap = false,
                        data = xAxisData
                    }
                },
                yAxis = new List<dynamic>()
                {
                    new { type = "value" }
                },
                series = new List<dynamic>()
                {
                    new {
                        name = "测量温度 (MeasureTemp)",
                        type = "line",
                        data = MeasureTempData
                    },
                    new {
                        name = "测量转速 (MeasureSpeedData)",
                        type = "line",
                        data = MeasureSpeedData
                    }
                }
            };

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 获取实验运行日志详情

        /// <summary>
        /// 获取实验运行日志详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> ExperimentRunLogDetail(SearchModel param)
        {
            Console.WriteLine("\n获取实验运行日志详情：ExperimentRunLogDetail");

            #region 参数校验

            Console.WriteLine($"Id：{param.Id}");
            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            // 获取详情数据
            var result = await BisExperimentRunLogDao.QuerySingle(w => w.Del_Flag == 0 && w.Id.Equals(param.Id));

            return new JsonResult(new ResultModel
            {
                Data = result
            });
        }

        #endregion

        #region 提交实验运行日志信息

        /// <summary>
        /// 提交实验运行日志信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> SubmitExperimentRunLog(UpdateModel param)
        {
            Console.WriteLine("\n提交实验运行日志信息：SubmitExperimentRunLog");

            #region 参数、数据校验

            Console.WriteLine($"ExpRunLogData：{param.ExpRunLogData}");

            if (param.ExpRunLogData == null)
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion 

            #region 获取所需数据

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            string orgId = string.Empty;
            string orgName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                orgName = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            #endregion

            #region 数据提交

            DateTime now = DateTime.Now;
            Guid guid = Guid.NewGuid();
            string newId = guid.ToString().ToUpper();
            int result = 0;

            result += await BisExperimentRunLogDao.Insert(new bis_experiment_runlog()
            {
                Id = newId,
                ExpId = param.ExpRunLogData.ExpId,
                ExpName = param.ExpRunLogData.ExpName,
                Title = param.ExpRunLogData.Title,
                Content = param.ExpRunLogData.Content,
                CreateUser = userId,
                CreateUserName = userName,
                CreateTime = now,
                Del_Flag = 0
            });

            return new JsonResult(new ResultModel
            {
                Msg = "新增成功"
            });

            #endregion 数据提交
        }

        #endregion

        #region 批量删除实验运行日志信息

        /// <summary>
        /// 批量删除实验运行日志信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> DelExperimentRunLog(UpdateModel param)
        {
            Console.WriteLine("\n批量删除实验运行日志信息：DelExperimentRunLog");

            #region 参数效验

            Console.WriteLine($"Id：{param.Id}");

            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;
            string[] idArray = param.Id.Split(',');

            int result = 0;
            foreach (var item in idArray)
            {
                Console.WriteLine(item);
                result += await BisExperimentRunLogDao.Update(u => new bis_experiment_runlog
                {
                    Del_Flag = 1
                }, w => w.Id.Equals(item));
            }

            return new JsonResult(new ResultModel
            {
                Msg = "删除成功",
                Data = result
            });
        }

        #endregion

        #region 获取预警记录列表

        /// <summary>
        /// 获取预警记录列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> WarningRecordList(SearchModel param)
        {
            Console.WriteLine("\n获取预警记录列表：WarningRecordList");

            #region 获取登录用户相关信息

            string orgId = string.Empty;
            string userId = string.Empty;
            string userRoleId = string.Empty;
            try
            {
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userRoleId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userRoleId").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            // 初始化数据查询表达式
            Expression<Func<bis_warning_record, bool>> expression = w => w.Del_Flag == 0;

            Console.WriteLine($"Type：{param.Type}");
            if (!string.IsNullOrEmpty(param.Type))
            {
                expression = expression.And(w => w.Type.Contains(param.Type));
            }

            Console.WriteLine($"Title：{param.Title}");
            if (!string.IsNullOrEmpty(param.Title))
            {
                expression = expression.And(w => w.Title.Contains(param.Title));
            }

            Console.WriteLine($"Content：{param.Content}");
            if (!string.IsNullOrEmpty(param.Content))
            {
                expression = expression.And(w => w.Content.Contains(param.Content));
            }

            dynamic result = null;
            if (param.Page != null && param.Limit != null)
            {
                result = await BisWarningRecordDao.QueryByWherePage(param.Page.Value, param.Limit.Value, expression, o => o.CreateTime, OrderByType.Desc);
            }
            else
            {
                result = await BisWarningRecordDao.QueryByWhere(expression, o => o.CreateTime, OrderByType.Desc);
            }
            var count = await BisWarningRecordDao.QueryCount(expression);

            return new JsonResult(new ResultModel
            {
                Count = count,
                Data = result
            });
        }

        #endregion

        #region 获取预警记录详情

        /// <summary>
        /// 获取预警记录详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> WarningRecordDetail(SearchModel param)
        {
            Console.WriteLine("\n获取预警记录详情：WarningRecordDetail");

            #region 参数校验

            Console.WriteLine($"Id：{param.Id}");
            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            return new JsonResult(new ResultModel
            {
                Data = await BisWarningRecordDao.QuerySingle(w => w.Del_Flag == 0 && w.Id.Equals(param.Id))
            });
        }

        #endregion

        #region 提交预警记录信息

        /// <summary>
        /// 提交预警记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> SubmitWarningRecord(UpdateModel param)
        {
            Console.WriteLine("\n提交预警记录信息：SubmitWarningRecord");

            #region 参数、数据校验

            Console.WriteLine($"Type：{param.Type}");
            Console.WriteLine($"Title：{param.Title}");
            Console.WriteLine($"Content：{param.Content}");

            if (string.IsNullOrEmpty(param.Type) ||
                string.IsNullOrEmpty(param.Title) ||
                string.IsNullOrEmpty(param.Content))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion 

            #region 获取所需数据

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            string orgId = string.Empty;
            string orgName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
                orgId = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgId").Value;
                orgName = Accessor.HttpContext.User.Claims.First(i => i.Type == "orgName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            #endregion

            #region 数据提交

            DateTime now = DateTime.Now;
            Guid guid = Guid.NewGuid();
            string newId = guid.ToString().ToUpper();

            int result = await BisWarningRecordDao.Insert(new bis_warning_record()
            {
                Id = newId,
                Type = param.Type,
                Title = param.Title,
                Content = param.Content,
                OrgGuid = orgId,
                OrgName = orgName,
                CreateUser = userId,
                CreateUserName = userName,
                CreateTime = now,
                UpdateUser = userId,
                UpdateUserName = userName,
                UpdateTime = now,
                Del_Flag = 0
            });

            return new JsonResult(new ResultModel
            {
                Msg = "新增成功"
            });

            #endregion 数据提交
        }

        #endregion

        #region 批量删除预警记录信息

        /// <summary>
        /// 批量删除预警记录信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        public async Task<JsonResult> DelWarningRecord(UpdateModel param)
        {
            Console.WriteLine("\n批量删除预警记录信息：DelWarningRecord");

            #region 参数效验

            Console.WriteLine($"Id：{param.Id}");

            if (string.IsNullOrEmpty(param.Id))
            {
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "必填参数不能为空"
                });
            }

            #endregion

            #region 获取登录用户相关信息

            string userId = string.Empty;
            string userName = string.Empty;
            try
            {
                userId = Accessor.HttpContext.User.Claims.First(i => i.Type == "userId").Value;
                userName = Accessor.HttpContext.User.Claims.First(i => i.Type == "userName").Value;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return new JsonResult(new ResultModel
                {
                    Success = false,
                    Msg = "Token已过期, 请重新登录"
                });
            }

            #endregion

            DateTime now = DateTime.Now;
            string[] idArray = param.Id.Split(',');

            int result = 0;
            foreach (var item in idArray)
            {
                Console.WriteLine(item);
                if (!item.Equals(userId))
                {
                    result += await BisWarningRecordDao.Update(u => new bis_warning_record
                    {
                        Del_Flag = 1,
                        UpdateUser = userId,
                        UpdateUserName = userName,
                        UpdateTime = now
                    }, w => w.Id.Equals(item));
                }
            }

            return new JsonResult(new ResultModel
            {
                Msg = "删除成功",
                Data = result
            });
        }

        #endregion

    }
}